package cur.nature.component.quartz.controller;

import cur.nature.component.quartz.model.Component_QuartzVO;
import cur.nature.framework.mvc.base.BaseAPI;
import cur.nature.framework.mvc.crud.CrudController;
import cur.nature.tinyorm.core.bean.PageBean;
import cur.nature.component.quartz.service.Component_QuartzService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 任务调度 Controller
 * 作者：Auto Generator By wujian
 * 生成日期：2023-10-11 21:44:26
 */
@Tag(name = "任务调度 接口")
@RestController
@RequestMapping("component/quartz/v1/api/Component_Quartz")
@ConditionalOnProperty( value = {"cur.component.quartz.controller.enable"})
public class Component_QuartzController extends CrudController<Component_QuartzService> {
    public Component_QuartzController(Component_QuartzService baseService) {
        super(baseService);
    }

    @Operation(summary = "查询 任务调度")
    @PostMapping("/list")
    public PageBean<Component_QuartzVO> list(@Valid @RequestBody Component_QuartzVO.list_Param param) throws Exception {
        PageBean<Component_QuartzVO> list = getService().list(param);
        return list;
    }

    @Operation(summary = "更新 任务调度")
    @PostMapping("/operate")
    public BaseAPI.SaveResult<Component_QuartzVO> save(@Valid @RequestBody List<Component_QuartzVO> param) throws Exception {
        int rows = getService().saveList(param);
        BaseAPI.SaveResult result = new BaseAPI.SaveResult();
        result.setRows(rows);
        result.setObject(rows == 0 ? null : param);
        return result;
    }


    @Operation(summary = "刷新任务调度")
    @PostMapping("/refresh")
    public BaseAPI.SaveResult refresh(@Valid @RequestBody BaseAPI.DeleteParam param) throws Exception {
        getService().refresh();
        BaseAPI.SaveResult result = new BaseAPI.SaveResult();
        result.setRows(1);
        return result;
    }

    @Operation(summary = "执行任务")
    @PostMapping("/runJob")
    public BaseAPI.SaveResult runJob(@Valid @RequestBody Component_QuartzVO param) throws Exception {
        getService().runJob(param);
        BaseAPI.SaveResult result = new BaseAPI.SaveResult();
        result.setRows(1);
        return result;
    }

}

